﻿using LD.Host;
using System;

using YTE.Control;

namespace LD.MES
{
    public partial class MesHelperSharpFrm : FrmBase
    {
        public MesHelperSharpFrm()
        {
            InitializeComponent();
            this.Shown += MesHelperSharpFrm_Shown;
        }

        private void MesHelperSharpFrm_Shown(object sender, EventArgs e)
        {
            Init();
        }
        private void Init()
        {
            this.txt_userCode.Text = (string)Cache.GetCache(CONST.SHARP_USERCODE);
            this.txt_machineCode.Text = (string)Cache.GetCache(CONST.SHARP_MACHINECODE);
            this.txt_lineCode.Text = (string)Cache.GetCache(CONST.SHARP_LINECODE);
            this.txt_keyenceIp.Text = (string)Cache.GetCache(CONST.SHARP_KEYENCEIP);
            this.txt_keyencePort.Text = (string)Cache.GetCache(CONST.SHARP_KEYENCEPORT);
            this.txt_mesUrl.Text = (string)Cache.GetCache(CONST.SHARP_MESURL);
        }
        public void Save()
        {
            Cache.SetCache(CONST.SHARP_USERCODE, this.txt_userCode.Text);
            Cache.SetCache(CONST.SHARP_MACHINECODE, this.txt_machineCode.Text);
            Cache.SetCache(CONST.SHARP_LINECODE, this.txt_lineCode.Text);
            Cache.SetCache(CONST.SHARP_KEYENCEIP, this.txt_keyenceIp.Text);
            Cache.SetCache(CONST.SHARP_KEYENCEPORT, this.txt_keyencePort.Text);
            Cache.SetCache(CONST.SHARP_MESURL, this.txt_mesUrl.Text);
         
        }

        private void btn_uploadTest_Click(object sender, EventArgs e)
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf - 8"" standalone=""yes""?>
                                <message>
                                    <message_id>LOGOFF_REQUEST</message_id> 
                                    <type_id>I</type_id>
                                    <system_byte>FAB02-1F-04-SRW-01-LOGOFF_REQUEST-20210312145311001</system_byte>
                                    <defect_list/>
                                    <material_list/>
                                    <glass_id>KNH0Z0010HFAC04</glass_id>
                                    <line_id>FAB02-1F-04</line_id>
                                    <eqp_id>FAB02-1F-04-SRW-01</eqp_id>
                                    <operator_id>OCTARE</operator_id>
                                    <glass_grade/>
                                    <is_scrap/>
                                </message>";
            Log4.Info("MES请求:" + xml);
            ActiveMQHelper activeMQHelper = new ActiveMQHelper();
            string xmlResponse = activeMQHelper.Send(xml, this.txt_machineCode.Text, true);
            if (string.IsNullOrEmpty(xmlResponse)) return;
            Log4.Info("MES返回:" + xmlResponse);
            this.txt_result.Text = "MES返回:" + xmlResponse;
        }
    }
}
